package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.PaymentRecord;
import com.qf.entity.PaymentRecordDTO;
import com.qf.service.PaymentRecordService;
import com.qf.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class PaymentRecordController {
    @Autowired
    private PaymentRecordService paymentRecordService; //财务管理



    @GetMapping("payment/record/find/all")
    public R findAll(){
        List<PaymentRecord> list =paymentRecordService.findAll();
        return R.ok(list);
    }

    @GetMapping("payment/record/page")
    public R findAll2(PaymentRecordDTO paymentRecordDTO){
        PageHelper.startPage(paymentRecordDTO.getPageNum(),paymentRecordDTO.getPageSize());
        List<PaymentRecord> list =paymentRecordService.findAll2(paymentRecordDTO);
        PageInfo<PaymentRecord> pageInfo = new PageInfo<>(list);
        return R.ok(pageInfo);
    }

    @PostMapping("/payment/record/add")
    public R addOrderFinance(@RequestBody PaymentRecord paymentRecord){
       boolean result = paymentRecordService.add(paymentRecord);
       if (result){
           return R.ok();
       }

        return R.fail();
    }

    @GetMapping("/payment/record/delete")
    public R deletePaymentRecord(int id){
        boolean result = paymentRecordService.deleteById(id);
        if (result){
            return R.ok();
        }
        return R.fail();
    }

    @PostMapping("/payment/record/update")
    public R updatePaymentRecord(@RequestBody PaymentRecord paymentRecord){
        boolean result = paymentRecordService.update(paymentRecord);
        if (result){
            return R.ok();
        }
        return R.fail();
    }
}
